package com.ruoyi.project.module.member.service.impl;

import com.ruoyi.project.module.common.dict.AppMemberGrade;
import com.ruoyi.project.module.common.dict.AppMemberStatus;
import com.ruoyi.project.module.common.utils.AuthUtils;
import com.ruoyi.project.module.member.domain.Member;
import com.ruoyi.project.module.member.mapper.MemberMapperPlus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 会员管理Service业务层处理(加强)
 *
 * @author Javen
 * @since 2020/11/28 11:56
 */
@Service("memberServicePlus")
public class MemberServicePlusImpl extends MemberServiceImpl {

    @Autowired
    private MemberMapperPlus memberMapper;

    @Override
    public int insertMember(Member member) {
        member.setPassword(AuthUtils.encodePassword(member.getPassword()));
        member.setPoints(0L);
        return super.insertMember(member);
    }

    @Override
    public int updateMember(Member member) {
        member.setPassword(AuthUtils.encodePassword(member.getPassword()));
        return super.updateMember(member);
    }

    /**
     * 通过手机号查找会员
     * @param mobile
     * @return
     */
    public Member selectMemberByMobile(String mobile){
        return memberMapper.selectMemberByMobile(mobile);
    }

    /**
     * 通过openId查找会员
     * @param openId
     * @return
     */
    public Member selectMemberByOpenId(String openId){
        return memberMapper.selectMemberByOpenId(openId);
    }

    /**
     * 微信登录-创建用户
     * @param member
     * @return
     */
    public int insertMemberByWechatAuth(Member member) {
        member.setStatus(AppMemberStatus.D_1_QY);
        member.setGrade(AppMemberGrade.D_0_PT);
        member.setPoints(0L);
        member.setCreateTime(new Date());
        return super.insertMember(member);
    }
}
